/*
 *  * Copyright (C) 2021 Huawei Device Co., Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.example.smileyrating.slice;

import com.example.smileyrating.LogUtil;
import com.example.smileyrating.ResourceTable;
import com.hsalf.smilerating.BaseRating;
import com.hsalf.smilerating.SmileRating;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.bundle.AbilityInfo;

public class SmileRatingAbilitySlice extends AbilitySlice
    implements SmileRating.OnSmileySelectionListener, SmileRating.OnRatingSelectedListener {

    private static final String TAG = SmileRatingAbilitySlice.class.getName();

    SmileRating mSmileRating;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_smile_rating);

        setDisplayOrientation(AbilityInfo.DisplayOrientation.LANDSCAPE);
        mSmileRating = (SmileRating) findComponentById(ResourceTable.Id_ratingView);
        mSmileRating.setOnSmileySelectionListener(this);
        mSmileRating.setOnRatingSelectedListener(this);

    }

    @Override
    public void onSmileySelected(@BaseRating.Smiley int smiley, boolean reselected) {
        switch (smiley) {
            case SmileRating.BAD:
                LogUtil.info(TAG, "Bad");
                break;
            case SmileRating.GOOD:
                LogUtil.info(TAG, "Good");
                break;
            case SmileRating.GREAT:
                LogUtil.info(TAG, "Great");
                break;
            case SmileRating.OKAY:
                LogUtil.info(TAG, "Okay");
                break;
            case SmileRating.TERRIBLE:
                LogUtil.info(TAG, "Terrible");
                break;
            case SmileRating.NONE:
                LogUtil.info(TAG, "None");
                break;
        }
    }

    @Override
    public void onRatingSelected(int level, boolean reselected) {
        LogUtil.info(TAG, "Rated as: " + level + " - " + reselected);
    }
}
